package xyy.d3erpapi.utils;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: Jincheng.Li
 * @Date: 2021/05/18/13:46
 * @Description:
 */
@Slf4j
@Component
public class WeChatUtil {
    private static final String WEBHOOK_URL_KEY = "c9af2441-b056-40ed-a1ed-ad048db85b2f";


    private static final String TAG = "【自定义告警】";
    private static final String WEBHOOK_URL = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=";


    public void sendWeChatMsg(String msg) {
        Map<String, String> heads = Maps.newHashMap();
        heads.put("Content-Type", "application/json");
        Map<String, Object> params = Maps.newHashMap();
        params.put("msgtype", "text");
        Map<String, Object> data = Maps.newHashMap();
        data.put("content", TAG + msg);
        params.put("text", data);
        String json = JSON.toJSONString(params);
        HttpRequest.post(WEBHOOK_URL + WEBHOOK_URL_KEY)
                .body(json)
                .execute();

    }
}